//
//  LogOnView.m
//  uMeng
//
//  Created by ZhuoLaiQiang@Gmail.com on 11-6-4.
//  Copyright 2011年 Mtime. All rights reserved.
//

#import "LogOnViewController.h"


@implementation LogOnViewController

@synthesize delegate = _delegate;

//- (void)loadView
//{
//    self.view = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease];
//    self.view.backgroundColor = [UIColor blackColor];
//    self.view.alpha = 0.3;
//}

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor clearColor];
    UIImageView *imageView  = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"logOn.png"]];
    imageView.userInteractionEnabled = YES;
   [self.view addSubview: imageView];
    
    //LogOnIfo.plist
    NSString *docs = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] ;
    NSString *subdir = [docs stringByAppendingPathComponent:@"LogOnIfo.plist"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath: subdir]) {
        _dic = [[NSMutableDictionary alloc] initWithContentsOfFile: subdir];
    }else
    {
        _dic = nil;
    }
    

    _userNameField = [[[UITextField alloc] initWithFrame: CGRectMake(65, 18, 205, 26)] autorelease];
    _userNameField.borderStyle = UITextBorderStyleNone;
    _userNameField.placeholder = @"请输入用户名";
    [self.view addSubview: _userNameField];
    if ([_dic objectForKey: @"memorizeUserName"]) {
        _userName.text = [_dic objectForKey: @"userName"];
    }
    
    
    _passWordField = [[[UITextField alloc] initWithFrame: CGRectMake(65, 56, 205, 26)] autorelease];
    _passWordField.borderStyle = UITextBorderStyleNone;
    _passWordField.placeholder = @"请输入密码";
    [self.view addSubview: _passWordField];
    if ([_dic objectForKey: @"autoLogOn"]) {
        _passWordField.text = [_dic objectForKey: @"passWord"];
        
    }
    
    _buttonLogOn = [UIButton buttonWithType: UIButtonTypeCustom];
    _buttonLogOn.frame = CGRectMake(40, 118, 75, 33);
    [_buttonLogOn setImage: [UIImage imageNamed: @"logOnbtn_cancl.png"] forState: UIControlStateHighlighted];
    [_buttonLogOn setImage: [UIImage imageNamed: @"logOnbtn_cancl_press.png"] forState: UIControlStateNormal];
    [self.view addSubview: _buttonLogOn];
    
    _buttonCancel = [UIButton buttonWithType: UIButtonTypeCustom];
    _buttonCancel.frame = CGRectMake(170, 118, 75, 33);
    [_buttonCancel setImage: [UIImage imageNamed:  @"logOnbtn_logon.png"] forState: UIControlStateHighlighted];
    [_buttonCancel setImage: [UIImage imageNamed: @"logOnbtn_logon_press.png"] forState: UIControlStateNormal];
    [self.view addSubview: _buttonCancel];
    
    _selectButton1 = [UIButton buttonWithType: UIButtonTypeCustom];
    _selectButton1.frame = CGRectMake(63, 85, 28, 24);
    [self.view addSubview: _selectButton1];
    [_selectButton1 addTarget: self action: @selector(memorizePassword:) forControlEvents: UIControlEventTouchUpInside];
    
    _selectButton2 = [UIButton buttonWithType: UIButtonTypeCustom];
    _selectButton2.frame = CGRectMake(174, 85, 28, 24);
    [_selectButton2 addTarget: self action: @selector(memorizePassword:) forControlEvents: UIControlEventTouchUpInside];
    [self.view addSubview: _selectButton2];
}

- (void)memorizePassword:(id)sender
{
    UIButton *button = (UIButton*)sender;
    if ([button backgroundImageForState: UIControlStateNormal]) 
    {
        [button setBackgroundImage: nil forState: UIControlStateNormal];
        if (button == _selectButton1) 
        {
                [_selectButton2 setBackgroundImage: nil forState: UIControlStateNormal];
        }
    }else
    {
        [button setBackgroundImage: [UIImage imageNamed: @"login_option_select.png"] forState: UIControlStateNormal];
        if (button == _selectButton2) 
        {
            [_selectButton1 setBackgroundImage: [UIImage imageNamed: @"login_option_select.png"] forState: UIControlStateNormal];
        }
    }
}

- (void)dealloc
{
    [_delegate release];
    [_dic release];
    [super dealloc];
}

@end
